package com.example.demo.test;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;

public class test4 {

    public static void main(String[] args) {
        HashMap<String, Student> map = new HashMap<>();
        Student student1 = new Student();
        student1.setName("lr");
        student1.setAge(18);
        student1.setCars(new ArrayList<Student.Car>());
        List<Student.Car> cars = student1.getCars();
        cars.add(new Student.Car("1",1,0));
        cars.add(new Student.Car("2",2,0));
        cars.add(new Student.Car("3",3,1));
        cars.add(new Student.Car("4",4,1));
        System.out.println(student1);
        /*map.put(student1.name,student1);

        *//*if(map.containsKey("lr")){
            Student lr = map.get("lr");
            List<Student.Car> cars1 = lr.getCars();
            cars1.add(new Student.Car(2,3,1));
        }*//*

        System.out.println(student1);*/
        student1.setCars(student1.getCars().stream().sorted((v1,v2)->v2.getSort()-v1.getSort()).collect(Collectors.toList()));
        System.out.println(student1);
        List<Student.Car> collect = student1.getCars().stream().filter(car -> car.getSort() == 1).collect(Collectors.toList());
        System.out.println(collect);
    }

    @Data
    @ToString
    public static class Student{
        String name;

        int age;

        List<Car> cars;

        @Data
        @ToString
        @AllArgsConstructor
        @NoArgsConstructor
        public static   class Car{
            String id;
            int id2;
            Integer sort;
        }
    }
}
